#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: data_copy_source_node.py 
@version:
@time: 2022/03/10 
"""
from TapClientCore.T04_logic.Dag02.node.node_base import NodeBase


class DataCopySourceNode(NodeBase):
    node = None

    def __init__(self, datasource_name):
        self.generate_node(datasource_name)

    def generate_node(self, datasource_name):
        from TapClientCore.T05_TM_feature.v2.TMF01_datasource.tmf_http import TMFHttp
        TMF = TMFHttp()
        # 通过datasource名称获取信息
        response = TMF.get_data_source_by_name(datasource_name)
        self.node = {
            'id': self.newId,
            'databaseType': response['database_type'],
            'connectionId': response['id'],
            'name': response['name'],
            'type': 'database',
            'attrs': {
                'position': [
                    -1000,
                    200
                ],
                'capabilities': [{"type": 10, "id": "new_field_event"}, {"type": 10, "id": "alter_field_name_event"},
                                 {"type": 10, "id": "alter_field_attributes_event"},
                                 {"type": 10, "id": "drop_field_event"},
                                 {"type": 11, "id": "release_external_function"},
                                 {"type": 11, "id": "batch_read_function"}, {"type": 11, "id": "stream_read_function"},
                                 {"type": 11, "id": "batch_count_function"},
                                 {"type": 11, "id": "timestamp_to_stream_offset_function"},
                                 {"type": 11, "id": "write_record_function"},
                                 {"type": 11, "id": "query_by_advance_filter_function"},
                                 {"type": 11, "id": "create_table_function"},
                                 {"type": 11, "id": "clear_table_function"}, {"type": 11, "id": "drop_table_function"},
                                 {"type": 11, "id": "create_index_function"},
                                 {"type": 11, "id": "alter_field_attributes_function"},
                                 {"type": 11, "id": "alter_field_name_function"},
                                 {"type": 11, "id": "drop_field_function"}, {"type": 11, "id": "new_field_function"},
                                 {"type": 11, "id": "get_table_names_function"}, {"type": 20, "id": "dml_insert_policy",
                                                                                  "alternatives": ["update_on_exists",
                                                                                                   "ignore_on_exists"]},
                                 {"type": 20, "id": "dml_update_policy",
                                  "alternatives": ["ignore_on_nonexists", "insert_on_nonexists"]}],
                'connectionType': response.get('connection_type'),
                'pdkHash': response.get('pdkHash'),
                'pdkType': 'pdk',
                'connectionName': datasource_name,
            },
            'migrateTableSelectType': 'custom',
            'tableSelectType': 'all',
        }


if __name__ == '__main__':
    t = DataCopySourceNode('auto_mysql')
